package com.iyunsir.goods.controller;

import com.iyunsir.common.vo.Result;
import com.iyunsir.goods.entity.Goods;
import com.iyunsir.goods.server.GoodsService;
import com.iyunsir.goods.vo.GoodsQuery;
import com.iyunsir.mem.entity.Mem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @GetMapping("/list")
    @ResponseBody
    public Result<Object> getGoodsList(GoodsQuery param) {
        List<Goods> list = goodsService.getGoodsList(param);
        Long count = goodsService.countGoodsList(param);
        return Result.success(list, count);
    }
    @PostMapping("")
    @ResponseBody
    public Result<Object> addGoods(Goods goods){
        goodsService.addGoods(goods);
        return Result.success("入库成功");

    }
    @DeleteMapping("/{ids}")
    @ResponseBody
    public Result<Object> deleteGoodsByIds(@PathVariable("ids") String ids){
        goodsService.deleteGoodsByIds(ids);
        return Result.success("删除成功！");
    }
    @GetMapping("/{id}")
    public String getGoodsById(@PathVariable("id") Integer id, Model model){
        Goods goods = goodsService.getGoodsById(id);
        model.addAttribute("goods",goods);
        return "enter/goodsEdit";
    }
    @PutMapping("")
    @ResponseBody
    public Result<Object> updateGoods(Goods goods){
        goodsService.updateGoods(goods);
        return Result.success("货物信息修改成功!");

    }
}
